home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8300 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  69 lines

  1. Path: tera.com!miles
  2. From: miles@phobos.tera.com (Miles Ohlrich)
  3. Newsgroups: comp.lang.c++,comp.lang.fortran
  4. Subject: Re: Calling C++ from FORTRAN on VMS
  5. Date: 16 Feb 1996 09:46:44 -0800
  6. Organization: Tera Computer Company
  7. Sender: miles@Tera.COM
  8. Distribution: world
  9. Message-ID: <4g2fu4$o2p@phobos.tera.com>
  10. References: <31239D17.3159@stsci.edu>
  11. NNTP-Posting-Host: phobos.tera.com
  12.  
  13.  
  14. In article <31239D17.3159@stsci.edu>, Scott Stallcup <stallcup@stsci.edu> writes:
  15. |> I need to call a C++ routine from a FORTRAN routine on both
  16. |> VAX/VMS and AXP/VMS platforms.   
  17. |> 
  18. |> Given the following example code, what compiler/linker options
  19. |> will resolve the c++ reference ?
  20. |> 
  21. |> ---------------------------------------------------------------
  22. |>       program tfor
  23. |> c
  24. |>       call tcxx ()
  25. |> c
  26. |>       end
  27. |> ---------------------------------------------------------------
  28. Try this:
  29.  
  30. #include <stdio.h>
  31. extern "C" void TCXX();
  32. void TCXX(void)  {
  33.    printf ("Hello World\n");
  34. }
  35.  
  36. or this:
  37.  
  38. #include <stdio.h>
  39. extern "C" void tcxx_();
  40. void tcxx_(void) {
  41.    printf("Hello World\n");
  42. }
  43.  
  44. Different platforms convert fortran function names differently: some convert
  45. to all caps; some add an underscore after the name.
  46. If you are doing mixed language programming on two separate platforms that
  47. use different naming conventions, you may have to use #ifdefs in the C++ code
  48. such as:
  49.  
  50. #include <stdio.h>
  51. #ifdef __sun__
  52.  extern "C" void tcxx_();
  53.  void tcxx_(void) {
  54.    printf("Hello World\n");
  55.  }
  56. #else
  57.  extern "C" void TCXX();
  58.  void TCXX(void) {
  59.    printf("Hello World\n");
  60.  }
  61. #endif
  62.  
  63. Note that you need the extern "C" line so that C++ doesn't do name mangling on 
  64. the function name. 
  65. I am not familiar with your specific platforms, however.
  66.  
  67.                         Miles Ohlrich
  68.                         Tera Computer Company
  69.